
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Employee;
import cn.edu.scau.cmi.hombio.domain.Inspection;
import cn.edu.scau.cmi.hombio.domain.InspectionException;
import cn.edu.scau.cmi.hombio.domain.PigHouse;
import cn.edu.scau.cmi.hombio.domain.Task;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class InspectionServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected InspectionService service;

	/**
	 * Instantiates a new InspectionServiceTest.
	 *
	 */
	public InspectionServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Return a count of all Inspection entity
	* 
	 */
	@Test
	public void countInspections() {
		Integer response = null;
		response = service.countInspections();
		// TODO: JUnit - Add assertions to test outputs of operation: countInspections
	}

	/**
	 * Operation Unit Test
	* Save an existing PigHouse entity
	* 
	 */
	@Test
	public void saveInspectionPigHouse() {
		// TODO: JUnit - Populate test inputs for operation: saveInspectionPigHouse 
		Integer id = 0;
		PigHouse related_pighouse = new cn.edu.scau.cmi.hombio.domain.PigHouse();
		Inspection response = null;
		response = service.saveInspectionPigHouse(id, related_pighouse);
		// TODO: JUnit - Add assertions to test outputs of operation: saveInspectionPigHouse
	}

	/**
	 * Operation Unit Test
	* Load an existing Inspection entity
	* 
	 */
	@Test
	public void loadInspections() {
		Set<Inspection> response = null;
		response = service.loadInspections();
		// TODO: JUnit - Add assertions to test outputs of operation: loadInspections
	}

	/**
	 * Operation Unit Test
	* Delete an existing Employee entity
	* 
	 */
	@Test
	public void deleteInspectionEmployee() {
		// TODO: JUnit - Populate test inputs for operation: deleteInspectionEmployee 
		Integer inspection_id = 0;
		Integer related_employee_id = 0;
		Inspection response = null;
		response = service.deleteInspectionEmployee(inspection_id, related_employee_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteInspectionEmployee
	}

	/**
	 * Operation Unit Test
	* Save an existing Employee entity
	* 
	 */
	@Test
	public void saveInspectionEmployee() {
		// TODO: JUnit - Populate test inputs for operation: saveInspectionEmployee 
		Integer id_1 = 0;
		Employee related_employee = new cn.edu.scau.cmi.hombio.domain.Employee();
		Inspection response = null;
		response = service.saveInspectionEmployee(id_1, related_employee);
		// TODO: JUnit - Add assertions to test outputs of operation: saveInspectionEmployee
	}

	/**
	 * Operation Unit Test
	* Save an existing InspectionException entity
	* 
	 */
	@Test
	public void saveInspectionInspectionExceptions() {
		// TODO: JUnit - Populate test inputs for operation: saveInspectionInspectionExceptions 
		Integer id_2 = 0;
		InspectionException related_inspectionexceptions = new cn.edu.scau.cmi.hombio.domain.InspectionException();
		Inspection response = null;
		response = service.saveInspectionInspectionExceptions(id_2, related_inspectionexceptions);
		// TODO: JUnit - Add assertions to test outputs of operation: saveInspectionInspectionExceptions
	}

	/**
	 * Operation Unit Test
	* Delete an existing Inspection entity
	* 
	 */
	@Test
	public void deleteInspection() {
		// TODO: JUnit - Populate test inputs for operation: deleteInspection 
		Inspection inspection = new cn.edu.scau.cmi.hombio.domain.Inspection();
		service.deleteInspection(inspection);
	}

	/**
	 * Operation Unit Test
	* Delete an existing Task entity
	* 
	 */
	@Test
	public void deleteInspectionTask() {
		// TODO: JUnit - Populate test inputs for operation: deleteInspectionTask 
		Integer inspection_id_1 = 0;
		Integer related_task_id = 0;
		Inspection response = null;
		response = service.deleteInspectionTask(inspection_id_1, related_task_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteInspectionTask
	}

	/**
	 * Operation Unit Test
	* Delete an existing PigHouse entity
	* 
	 */
	@Test
	public void deleteInspectionPigHouse() {
		// TODO: JUnit - Populate test inputs for operation: deleteInspectionPigHouse 
		Integer inspection_id_2 = 0;
		Integer related_pighouse_id = 0;
		Inspection response = null;
		response = service.deleteInspectionPigHouse(inspection_id_2, related_pighouse_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteInspectionPigHouse
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findInspectionByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findInspectionByPrimaryKey 
		Integer id_3 = 0;
		Inspection response = null;
		response = service.findInspectionByPrimaryKey(id_3);
		// TODO: JUnit - Add assertions to test outputs of operation: findInspectionByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Delete an existing InspectionException entity
	* 
	 */
	@Test
	public void deleteInspectionInspectionExceptions() {
		// TODO: JUnit - Populate test inputs for operation: deleteInspectionInspectionExceptions 
		Integer inspection_id_3 = 0;
		Integer related_inspectionexceptions_id = 0;
		Inspection response = null;
		response = service.deleteInspectionInspectionExceptions(inspection_id_3, related_inspectionexceptions_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteInspectionInspectionExceptions
	}

	/**
	 * Operation Unit Test
	* Save an existing Inspection entity
	* 
	 */
	@Test
	public void saveInspection() {
		// TODO: JUnit - Populate test inputs for operation: saveInspection 
		Inspection inspection_1 = new cn.edu.scau.cmi.hombio.domain.Inspection();
		service.saveInspection(inspection_1);
	}

	/**
	 * Operation Unit Test
	* Save an existing Task entity
	* 
	 */
	@Test
	public void saveInspectionTask() {
		// TODO: JUnit - Populate test inputs for operation: saveInspectionTask 
		Integer id_4 = 0;
		Task related_task = new cn.edu.scau.cmi.hombio.domain.Task();
		Inspection response = null;
		response = service.saveInspectionTask(id_4, related_task);
		// TODO: JUnit - Add assertions to test outputs of operation: saveInspectionTask
	}

	/**
	 * Operation Unit Test
	* Return all Inspection entity
	* 
	 */
	@Test
	public void findAllInspections() {
		// TODO: JUnit - Populate test inputs for operation: findAllInspections 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Inspection> response = null;
		response = service.findAllInspections(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllInspections
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
